﻿package bdz.projects.lavender.doi.ui
{
	import bdz.common.events.*;
	import bdz.common.model.AppEnvironment;
	import flash.external.ExternalInterface;
	import org.papervision3d.view.layer.ViewportLayer;
	
	import flash.display.*;
	import flash.events.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	
	import org.papervision3d.Papervision3D;
	import org.papervision3d.cameras.*;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	
	/**
	 * ...
	 * @author ...
	 */
	public class DOIPlanesView extends BasicView
	{
		
		
		private var _maincontainer:DisplayObject3D;
		private var _currentPlane:DOIPlanesHolder;
		private var _introPlane:DOIIntroAnimations;
		private var _navPlane:DOINavigationView;
		private var _catPlane:DOICategoryPlaneView;
		private var _modPlane:DOIModulePlaneView;
		private var _currentCatPlane:DOICategoryPlaneView;
		private var _currentModPlane:DOIModulePlaneView;
		private var _preloaderPlane:Plane;
		private var _preloaderMC:MovieClip;
		private var _preloaderMat:MovieMaterial;
		private var _hasPreloader:Boolean = false;
		
		private var _skipperPlane:Plane;
		private var _skipperMC:MovieClip;
		private var _skipperMat:MovieMaterial;
		private var _hasSkipper:Boolean = false;
		
		private var _replayPlane:Plane;
		private var _replayMC:MovieClip;
		private var _replayMat:MovieMaterial;
		private var _hasReplay:Boolean = false;
		
		private var _tilt:Boolean = true;
		private var _env:AppEnvironment = AppEnvironment.getEnv();
		public var _navCreated:Boolean = false;
		public var _queuedShortcut:Object = null;
		
		public function DOIPlanesView(vwidth:Number = 640, vheight:Number = 480, scaleToStage:Boolean = true, interactive:Boolean = true, cam:String = "Spring") {
			Papervision3D.PAPERLOGGER.unregisterLogger(Papervision3D.PAPERLOGGER.traceLogger);
			super(vwidth, vheight, scaleToStage, interactive, cam);	
			addEventListener(Event.ADDED_TO_STAGE, initializeComponent);
		}
		protected function initializeComponent(evt:Event):void {
			/**
			 * CREATE CONTAINER
			 */
			//trace(CameraType.SPRING);
			_camera.focus = 50;
			
			_maincontainer = new DisplayObject3D("_maincontainer");
			//_maincontainer.visible = false;
			
			_maincontainer.z = accurateZ;
			//_maincontainer.y = 50;
			scene.addChild(_maincontainer, "_maincontainer");
			
			
			
			onStageResize();
		}
		public function onStageResize(evt:Event = null):void {
			
		}
		public function render(evt:*= null):void {
			/**
			 * CAN BE REPLACED WITH PRESET TILTING
			 */
			
			
			if(false){
				var xdiff:Number  = (mouseX - stage.stageWidth / 2) / 60;	
				var ydiff:Number  = (mouseY - stage.stageHeight / 2) / 100;
				
				if (Math.abs(xdiff) > 20) {
					xdiff = xdiff > 0 ? 20 : -20;
				}
				if (Math.abs(ydiff) > 8) {
					ydiff = ydiff > 0 ? 8 : -8;
				}
				
				
				var poslimit:Number = 15;
				
				var distrotx:Number = xdiff  - _maincontainer.rotationY;
				var distroty:Number = ydiff - _maincontainer.rotationX;
				
				var distx:Number = xdiff - _maincontainer.x;
				var disty:Number = ydiff - _maincontainer.y;
				
				_maincontainer.rotationY += distrotx * .04;
				_maincontainer.rotationX += distroty * .04;
				
				
				_maincontainer.y += ydiff * .03;
				_maincontainer.x -= xdiff * .03;
				
			
				if (_maincontainer.x <= -poslimit) {
					_maincontainer.x = -poslimit;
				}else if (_maincontainer.x >= poslimit) {
					_maincontainer.x = poslimit;
				}
				
				if (_maincontainer.y <= -poslimit) {
					_maincontainer.y = -poslimit;
				}else if (_maincontainer.y >= poslimit) {
					_maincontainer.y = poslimit;
				}
				
				
			}
			renderer.renderScene(scene, camera, viewport);
			
			
		}
		private function renderLayer():void {
			
		}
		private function cleanUpPlane(doipl:DOIPlane):void {
			
			if (doipl) {
				var ismod:Boolean = doipl.name.indexOf("module") != -1;
				doipl.remove(_maincontainer);
				doipl = null;
				if (ismod) {
					_tilt = true;
					/*
					_moduleOnly = false;
					viewport.containerSprite.removeLayer(_moduleLayer);
					*/
					try{
						_modPlane = null;
					}catch(e:Error){}
				}else {
					
					try{
						_catPlane = null;
					}catch(e:Error){}
				}
			}
			
			
			
		}
		public function goHome(dispatch:Boolean = true ):void {
			destroySkipperReplay();
			var tme:Number = 0;
			if (_modPlane || _currentModPlane) {
				setTimeout(cleanUpPlane, tme, _modPlane);
				setTimeout(cleanUpPlane, tme, _currentModPlane);
				tme += 100;
			}
			if (_catPlane || _currentCatPlane) {
				setTimeout(cleanUpPlane, tme, _catPlane);
				setTimeout(cleanUpPlane, tme, _currentCatPlane);
				tme += 100;	
			}
				
			
			setTimeout(_navPlane.returnToZero, tme);
			if(dispatch){
				dispatchEvent(new GenericEvent("ContentChanged", "home"));
			}
		}
		
		private function onMainNavigationClicked(evt:GenericEvent):void {
			dispatchEvent(new GenericEvent("MainNavClicked", evt.data));
		}
		private function onCategoryPlaneClicked(evt:GenericEvent):void {
			dispatchEvent(new GenericEvent("CatPlaneClicked", evt.data));
			dispatchEvent(new GenericEvent("PlaneStateChange"));
		}
		public function killIntroPlane():void {
			try{
				_introPlane.kill();
			}catch (e:Error) {
				
			}
		}
		public function createIntroPlane():void {
			
			_introPlane = new DOIIntroAnimations();
			_introPlane.pcontainer = _maincontainer;
			_maincontainer.addChild(_introPlane);
		}
	
		public function createNavigationView(arr:Array, rndr:String):void {
			if(_navPlane == null){
				_navPlane = new DOINavigationView(arr);
				_navPlane.renderer  = rndr;
				_navPlane.viewport = viewport;
				_navPlane.addEventListener(GenericEvent.CLICKED, onMainNavigationClicked);
				_navPlane.addEventListener("BackAction", onMainNavigationBack);
				_navPlane.addEventListener(GenericEvent.GENERATED, navCreated);
				_maincontainer.addChild(_navPlane);
				if(_queuedShortcut == null){
					dispatchEvent(new GenericEvent("ContentChanged", "home"));
				}
			}
		}
		private function navCreated(evt:GenericEvent):void {
			_navCreated = true;
			if (_queuedShortcut) {
				dispatchEvent(new GenericEvent("ResolveDeepLink", _queuedShortcut));
			}
		}
		public function triggerCategoryNav(n:Number):void {
			if (_catPlane) {
				_catPlane.showMenuIndex(n);
			}
			
		}
		private function onMainNavigationBack(evt:GenericEvent):void {
			goHome();
			dispatchEvent(new GenericEvent("PlaneStateChange"));
		}
		
		public function onCategoryPlaneBack(evt:GenericEvent = null):void {
			cleanUpPlane(_modPlane);
			cleanUpPlane(_currentModPlane);
			setTimeout(_catPlane.moveAndFlipForward, 100);
			setTimeout(_navPlane.simpleMoveForward, 200);
			dispatchEvent(new GenericEvent("PlaneStateChange"));
			dispatchEvent(new GenericEvent("BackToCategory", { obj:_catPlane.contentObject, played:_catPlane.introPlayed } ));
			dispatchEvent(new GenericEvent("ContentChanged", _catPlane.contentObject));
		}
		
		private function applyNewCatReference(evt:GenericEvent):void {	
			_catPlane = _currentCatPlane;
		}
		private function resolveCategoryCreation(obj:Object, rndr:String, backed:Number = 0, ishow:Boolean = false):void {
			cleanUpPlane(_currentCatPlane);
			cleanUpPlane(_catPlane);
			_currentCatPlane = new DOICategoryPlaneView("category_" + new Date().getTime(), obj, backed, ishow);
			_currentCatPlane.addEventListener(GenericEvent.CLICKED, onCategoryPlaneClicked);
			_currentCatPlane.addEventListener("BackAction", onCategoryPlaneBack);
			_currentCatPlane.addEventListener(GenericEvent.GENERATED, applyNewCatReference);
			_currentCatPlane.renderer = rndr;
			_currentCatPlane.viewport = viewport;
			_currentCatPlane.planeView = this;
			
			_maincontainer.addChild(_currentCatPlane);
		}
		public function createCategoryPlane(obj:Object, rndr:String, ishow:Boolean = false):void {
			_navPlane.moveAndFlipBack();
			try{
				_catPlane.hideMenu();
			}catch(e:Error){}
			resolveCategoryCreation(obj, rndr, 0, ishow);
		}
		public function stopCategoryAnimation():void {
			if (_catPlane) {
				_catPlane.stopAnimations();
			}
		}
		public function showCategoryAnimation(linkage:String):void {
			if (_catPlane) {
				_catPlane.showCategoryAnimation(linkage);
			}
		}
		private function applyNewModuleReference(evt:GenericEvent):void {
			_modPlane = _currentModPlane;
			_tilt = false;
			//stage.quality = StageQuality.MEDIUM;
			TweenMax.to(_maincontainer, .8, { rotationY:0, rotationX:0, x:0, y:0, ease:Strong.easeInOut, onUpdate:singleRender} );
		}

		private function onContentChanged(evt:GenericEvent):void {
			
			dispatchEvent(evt);
		}
		
		private function resolveModuleCreation(obj:Object, rndr:String, defstep:Number = 0):void {
			
			cleanUpPlane(_currentModPlane);
			cleanUpPlane(_modPlane);
			_modPlane = new DOIModulePlaneView("module_"+new Date().getTime(), obj, defstep);
			//_currentModPlane.addEventListener(GenericEvent.GENERATED, applyNewModuleReference);
			_modPlane.addEventListener("ContentChanged", onContentChanged);
			_modPlane.planeView = this;
			_modPlane.renderer = rndr;
			_modPlane.viewport = viewport;
			_maincontainer.addChild(_modPlane);
			/*
			_moduleLayer = new ViewportLayer(viewport, _currentModPlane);
			viewport.containerSprite.addLayer(_moduleLayer);
			_renderables.push(_moduleLayer);
			*/
		}
		public function createModulePlane(obj:Object, rndr:String, defstep:Number = 0):void {
			_navPlane.simpleMoveBack(100, 60, 2);
			try{
				_catPlane.moveAndFlipBack();
			}catch (e:Error) {
				_currentCatPlane.moveAndFlipBack();
			}
			resolveModuleCreation(obj, rndr, defstep);
		}
		
		public function suppressRendering():void {
			removeEventListener(Event.ENTER_FRAME, render);
		}
		public function checkForValidCatVideo(obj:Object):Boolean {
			var ret:Boolean = true;
		
			if (_modPlane && _modPlane.z == 0) {
				
				if (_catPlane && _catPlane.contentObject.id == obj.id) {
					return false;
				}
				if (_currentCatPlane && _currentCatPlane.contentObject.id == obj.id) {
					return false;
				}
			}
			
			return ret;
		}
		public function showNewCategory(obj:Object, rndr:String, ishow:Boolean = true):void {
			try{
				_catPlane.hideMenu();
			}catch(e:Error){}
			if (_modPlane && _modPlane.z == 0) {
				if (_catPlane.contentObject.shortname == obj.shortname) {
					setTimeout(cleanUpPlane, 200, _modPlane);
					setTimeout(cleanUpPlane, 200, _currentModPlane);
					_navPlane.simpleMoveForward();
					_catPlane.moveAndFlipForward();
					
				}else {
					_navPlane.simpleMoveForward();
					setTimeout(cleanUpPlane, 50, _modPlane);
					setTimeout(cleanUpPlane, 50, _currentModPlane);
					setTimeout(cleanUpPlane, 150, _catPlane);
					setTimeout(cleanUpPlane, 150, _currentCatPlane);
					setTimeout(resolveCategoryCreation, 250, obj, rndr, ishow);
				}
			}else if (_catPlane && _catPlane.z == 0) {
				if (_catPlane.contentObject.shortname != obj.shortname) {
					setTimeout(cleanUpPlane, 0, _catPlane);
					setTimeout(cleanUpPlane, 0, _currentCatPlane);
					setTimeout(resolveCategoryCreation, 100, obj, rndr, ishow);
				}
			}else {
				_navPlane.moveAndFlipBack();
				setTimeout(resolveCategoryCreation, 50, obj, rndr, ishow);
			}
		}
		public function showNewModule(obj:Object):void {
			
			if(_modPlane && _modPlane.z == 0){
				if (_modPlane.contentObject.shortname == obj.shortname) {
					_modPlane.changePlay(0);
				}else if (_catPlane.contentObject.shortname == obj.parent.shortname) {
					setTimeout(cleanUpPlane, 200, _modPlane);
					setTimeout(cleanUpPlane, 200, _currentModPlane);
					setTimeout(resolveModuleCreation, 600, obj, "ModViewFrame");
				}else {
					setTimeout(cleanUpPlane, 0, _modPlane);
					setTimeout(cleanUpPlane, 0, _currentModPlane);
					setTimeout(cleanUpPlane, 200, _catPlane);
					setTimeout(cleanUpPlane, 200, _currentCatPlane);
					
					setTimeout(resolveCategoryCreation, 600, obj.parent, "CatViewBG", 1);
					setTimeout(resolveModuleCreation, 1000, obj, "ModViewFrame");
				}
			}else if (_catPlane && _catPlane.z == 0) {
				if (_catPlane.contentObject.shortname == obj.parent.shortname) {
					_navPlane.simpleMoveBack(100, 60, 2);
					setTimeout(cleanUpPlane, 200, _modPlane);
					setTimeout(cleanUpPlane, 200, _currentModPlane);
					setTimeout(resolveModuleCreation, 600, obj, "ModViewFrame");
				}else {
					_navPlane.simpleMoveBack(100, 60, 2);
					setTimeout(cleanUpPlane, 50, _modPlane);
					setTimeout(cleanUpPlane, 50, _currentModPlane);
					setTimeout(cleanUpPlane, 350, _catPlane);
					setTimeout(cleanUpPlane, 350, _currentCatPlane);
					
					setTimeout(resolveCategoryCreation, 700, obj.parent, "CatViewBG", 1);
					setTimeout(resolveModuleCreation, 1000, obj, "ModViewFrame");
				}
			}else {
				
				_navPlane.moveAndFlipBack(100 * 2, 60 * 2);
				setTimeout(resolveCategoryCreation, 50, obj.parent, "CatViewBG", 1);
				setTimeout(resolveModuleCreation, 350, obj, "ModViewFrame");
			}
			
		}
		public function showNewChapter(obj:Object):void {
			
			if (_modPlane && _modPlane.z == 0) {
				
				if (_modPlane.contentObject.shortname == obj.parent.shortname) {
					//resolveModuleCreation(obj.parent, "ModViewFrame", obj.index);
					_modPlane.changePlay(obj.index);
				}else if (_catPlane.contentObject.id == obj.parent.parent.shortname) {
					
					setTimeout(cleanUpPlane, 200, _modPlane);
					setTimeout(cleanUpPlane, 200, _currentModPlane);
					setTimeout(resolveModuleCreation, 600, obj.parent, "ModViewFrame", obj.index);
					
				}else {
					
					setTimeout(cleanUpPlane, 0, _modPlane);
					setTimeout(cleanUpPlane, 0, _currentModPlane);
					setTimeout(cleanUpPlane, 200, _catPlane);
					setTimeout(cleanUpPlane, 200, _currentCatPlane);
					
					setTimeout(resolveCategoryCreation, 600, obj.parent.parent, "CatViewBG", 1);
					setTimeout(resolveModuleCreation, 1000, obj.parent, "ModViewFrame", obj.index);
					
				}
			}else if (_catPlane && _catPlane.z == 0) {
				if (_catPlane.contentObject.shortname == obj.parent.parent.shortname) {
					
					_navPlane.simpleMoveBack(100, 60, 2);
					_catPlane.moveAndFlipBack();
					setTimeout(cleanUpPlane, 100, _modPlane);
					setTimeout(cleanUpPlane, 100, _currentModPlane);
					
					setTimeout(resolveModuleCreation, 400, obj.parent, "ModViewFrame", obj.index);
				}else {
					
					_navPlane.simpleMoveBack(100, 60, 2);
					setTimeout(cleanUpPlane, 50, _modPlane);
					setTimeout(cleanUpPlane, 50, _currentModPlane);
					setTimeout(cleanUpPlane, 350, _catPlane);
					setTimeout(cleanUpPlane, 350, _currentCatPlane);
					
					setTimeout(resolveCategoryCreation, 700, obj.parent.parent, "CatViewBG", 1);
					setTimeout(resolveModuleCreation, 1000, obj.parent, "ModViewFrame", obj.index);
				}
			}else {
				
				_navPlane.moveAndFlipBack(100 * 2, 60 * 2);
				
				setTimeout(resolveCategoryCreation, 50, obj.parent.parent, "CatViewBG", 1);
				setTimeout(resolveModuleCreation, 350, obj.parent, "ModViewFrame", obj.index);
			}
			
		}
		public function setPreloaderValue(n:Number):void {
			try {
				if (_preloaderPlane.rotationY == 0) {
					_preloaderMC.setProgress(n);
				}
				
			}catch (e:Error) {
				
			}
		}
		private function preloaderRolls(evt:InteractiveScene3DEvent):void {
			
			if (evt.target == _skipperPlane) {
				_skipperMC.roll.visible = (evt.type == InteractiveScene3DEvent.OBJECT_OVER);
				_skipperMC.defmat.drawBitmap();
			}
			if (evt.target == _replayPlane) {
				_replayMC.roll.visible = (evt.type == InteractiveScene3DEvent.OBJECT_OVER);
				_replayMC.defmat.drawBitmap();
			}
			viewport.buttonMode = evt.type == InteractiveScene3DEvent.OBJECT_OVER;
		}
		private function preloaderClick(evt:InteractiveScene3DEvent):void {
			viewport.buttonMode = false;
			dispatchEvent(new GenericEvent("CancelPreloader"));
			
		}
		private function skipperClick(evt:InteractiveScene3DEvent):void {
			
			viewport.buttonMode = false;
			try{
				_catPlane.clearAnimations();
				
			}catch (e:Error) {
				
			}
			dispatchEvent(new GenericEvent("SkipVideo"));
		}
		public function createSkipper(mc:MovieClip, dropz:Number = -100, xoffset:Number = 0, yoffset:Number = 0 ):void {
			if (!_hasSkipper) {
				var dm:DOIMain = _env.getSetting("application");
				_skipperMC = mc;
				_skipperMat = new MovieMaterial(_skipperMC, true, true, true);
				_skipperMC.defmat = _skipperMat;
				_skipperMat.doubleSided = false;
				_skipperMat.smooth = true;
				_skipperMat.interactive = true;
				_skipperPlane = new Plane(_skipperMat, _skipperMC.width, _skipperMC.height, 3, 3);
				_skipperPlane.rotationY = -180;
				_skipperPlane.z = -400;
				_skipperPlane.y = -130 + yoffset;
				if (dm._currentvid.indexOf("Category2") != -1 || dm._currentvid.indexOf("Category4") != -1) {
					_skipperPlane.x = -240;
				}else{
					_skipperPlane.x = 240 + xoffset;
				}
				_skipperPlane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, preloaderRolls);
				_skipperPlane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, preloaderRolls);
				_skipperPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, skipperClick);
				_maincontainer.addChild(_skipperPlane, "skipper");
				
				TweenMax.to(_skipperPlane, 1, {delay:1, rotationY:0, z: dropz, ease:Strong.easeInOut } );
				_hasSkipper = true;
			}else {
				TweenMax.killAllDelayedCalls();
				TweenMax.killTweensOf(_skipperPlane);
				TweenMax.to(_skipperPlane, .8, {scale:1, rotationY:0, z: dropz, ease:Strong.easeInOut } );
			}
		}
		
		private function replayClick(evt:InteractiveScene3DEvent):void {
			viewport.buttonMode = false;
			_catPlane.hideMenu();
			dispatchEvent(new GenericEvent("ReplayCatVideo", _catPlane.contentObject));
			
		}
		public function createReplay(mc:MovieClip, dropz:Number = -100):void {
			if (!_hasReplay) {
				var dm:DOIMain = _env.getSetting("application");
				_replayMC = mc;
				_replayMat = new MovieMaterial(_replayMC, true, true, true);
				_replayMC.defmat = _replayMat;
				_replayMat.doubleSided = false;
				_replayMat.smooth = true;
				_replayMat.interactive = true;
				_replayPlane = new Plane(_replayMat, _replayMC.width, _replayMC.height, 3, 3);
				_replayPlane.rotationY = -180;
				_replayPlane.z = -400;
				_replayPlane.y = -130;
				if (dm._currentvid.indexOf("Category2") != -1 || dm._currentvid.indexOf("Category4") != -1) {
					_replayPlane.x = -240;
				}else{
					_replayPlane.x = 240;
				}
				
				_replayPlane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, preloaderRolls);
				_replayPlane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, preloaderRolls);
				_replayPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, replayClick);
				_maincontainer.addChild(_replayPlane, "replay");
				TweenMax.to(_replayPlane, 1, {rotationY:0, z: dropz, ease:Strong.easeInOut } );
				_hasReplay = true;
			}else {
				TweenMax.killAllDelayedCalls();
				TweenMax.killTweensOf(_replayPlane);
				TweenMax.to(_replayPlane, .8, {scale:1, rotationY:0, z: dropz, ease:Strong.easeInOut } );
			}
		}
		public function createPreloader(mc:MovieClip, dropz:Number = -100, showskip:Boolean = true):void {
			
			try {
				TweenMax.killAllDelayedCalls();
				
				TweenMax.killTweensOf(_preloaderPlane);
			}catch (e:Error) {
				
			}
			if (!_hasPreloader) {
				
				_preloaderMC = mc;
				_preloaderMC.skip.visible = showskip;
				
				_preloaderMat = new MovieMaterial(_preloaderMC, true, true, true);
				_preloaderMat.doubleSided = false;
				_preloaderMat.smooth = true;
				_preloaderMat.interactive = showskip;
				_preloaderPlane = new Plane(_preloaderMat, _preloaderMC.width, _preloaderMC.height, 3, 3);
				_preloaderPlane.rotationY = -180;
				_preloaderPlane.z = -400;
				_preloaderPlane.y = 10;
				_preloaderPlane.scale = 2;
				if(showskip){
					_preloaderPlane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, preloaderRolls);
					_preloaderPlane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, preloaderRolls);
					_preloaderPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, preloaderClick);
				}
				_maincontainer.addChild(_preloaderPlane);
				
				TweenMax.to(_preloaderPlane, 1, { scale:1, delay:1, rotationY:0, z: dropz, ease:Strong.easeInOut} );
				_hasPreloader = true;
				
			}else {
				
				TweenMax.killAllDelayedCalls();
				TweenMax.killTweensOf(_preloaderPlane);
				TweenMax.to(_preloaderPlane, .8, { scale:1, rotationY:0, z: dropz, ease:Strong.easeInOut } );
				/*
				_hasPreloader = false;
				createPreloader(mc, dropz, showskip);
				*/
			}
		}
		
		private function cleanUpPreloader():void {
			try {
				
				_maincontainer.removeChild(_preloaderPlane);
				_preloaderMat.destroy();
				_preloaderMC = null;
				_preloaderPlane = null;
				_preloaderMat = null;
			}catch(e:Error){}
			
		}
		public function destroySkipperReplay():void {
			
			try{
				cleanUpReplay();
			}catch (e:Error) { }
			try {
				cleanUpSkipper();
			}catch (e:Error){}
			
		}
		private function cleanUpReplay ():void {
			_maincontainer.removeChild(_replayPlane);
			_replayMat.destroy();
			_replayMC = null;
			_replayPlane = null;
			_replayMat = null;
			_hasReplay = false;
		}
		public function destroyReplay():void {
			if (_hasReplay) {
				TweenMax.killAllDelayedCalls();
				TweenMax.killTweensOf(_replayPlane);
				//TweenMax.to(_replayPlane, 1, {scale:2,  z:0, rotationY: -180, ease:Strong.easeInOut, z: -100, onComplete:cleanUpReplay, overwrite:false } );
				TweenMax.to(_replayPlane, 1, {scale:2,  z:0, rotationY: -180, ease:Strong.easeInOut, z: -100, onComplete:cleanUpReplay } );
			}
		}
		private function cleanUpSkipper():void {
			try{
				_maincontainer.removeChild(_skipperPlane);
				_skipperMat.destroy();
			}catch (e:Error) {
				
			}
			_skipperMC = null;
			_skipperPlane = null;
			_skipperMat = null;
			_hasSkipper = false;
			
		}
		public function destroySkipper():void {
			if (_hasSkipper) {
				TweenMax.killAllDelayedCalls();
				TweenMax.killTweensOf(_skipperPlane);
				TweenMax.to(_skipperPlane, 1, {scale:2,  z:0, rotationY: -180, ease:Strong.easeInOut, z: -100, onComplete:cleanUpSkipper, overwrite:false } );
				//TweenMax.to(_skipperPlane, 1, {scale:2,  z:0, rotationY: -180, ease:Strong.easeInOut, z: -100, onComplete:cleanUpSkipper } );
			}
		}
		public function quickDestroyPreloader():void {
			
			TweenMax.killAllDelayedCalls();
			
			TweenMax.killTweensOf(_preloaderPlane);
			_hasPreloader = false;
			cleanUpPreloader();
		}
		public function destroyPreloader():void {
			if (_hasPreloader) {
				_hasPreloader = false;
				TweenMax.killAllDelayedCalls();
				
				TweenMax.killTweensOf(_preloaderPlane);
				TweenMax.to(_preloaderPlane, .6, {scale:2,  z:-800, rotationY: -180, ease:Strong.easeInOut, z: -100, onComplete:cleanUpPreloader, overwrite:false } );
				//TweenMax.to(_preloaderPlane, .6, {scale:2,  z:-800, rotationY: -180, ease:Strong.easeInOut, z: -100, onComplete:cleanUpPreloader} );
			}
		}
		public function get accurateZ():Number {
			return (camera.zoom * camera.focus) - Math.abs(camera.z);
		}
		public function get categoryPlane():DOICategoryPlaneView {
			return _catPlane;
		}
		public function get modulePlane():DOIModulePlaneView {
			return _modPlane;
		}
		public function get introPlane():DOIIntroAnimations {
			return _introPlane;
		}
		public function get navigationPlane():DOINavigationView {
			return _navPlane;
		}
	}
	
}